package file;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

import org.junit.Test;

import entity.Person;

public class TestObjectSteam {

	@Test
	public void objectOutputSteam() throws IOException {

		Person person = new Person("Rose", "18");

		OutputStream outputStream = new FileOutputStream("d:\\obj.txt");

		ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

		objectOutputStream.writeObject(person);

		objectOutputStream.close();
	}

	@Test
	public void objectIntputSteam() throws IOException, ClassNotFoundException {

		InputStream inputStream = new FileInputStream("d:\\obj.txt");

		ObjectInputStream objectOutputStream = new ObjectInputStream(inputStream);

		Object object = objectOutputStream.readObject();
		System.out.println(object);
		objectOutputStream.close();
	}
}
